<template>
  <div class="article-detail-page" v-show="article.id">
    <nav class="nav"><span class="back" @click="$router.go(-1)">&lt;</span> 面经详情</nav>
    <header class="header">
      <h1>{{article.stem}}</h1>
      <p>{{article.createdAt}} | {{article.views}} 浏览量 | {{article.likeCount}} 点赞数</p>
      <p>
        <img
          :src="article.creatorAvatar"
          alt=""
        />
        <span>{{article.creatorName}}</span>
      </p>
    </header>
    <main class="body">
      {{article.content}}
    </main>
  </div>
</template>

<script>
// 请求地址: https://mock.boxuegu.com/mock/3083/articles/:id
// 请求方式: get
// import axios from "axios";

export default {
  name: "ArticleDetailPage",
  data() {
    return {
      article: ''
    }
  },
  // 使用axios请求数据
  // async created() {
  // 动态路由传参
  //   const {data: {result}} = await axios.get(`https://mock.boxuegu.com/mock/3083/articles/${this.$route.params.id}`)
  // 参训参数传参
  //   const {data: {result}} = await axios.get(`https://mock.boxuegu.com/mock/3083/articles/${this.$route.query.id}`)
  //   console.log(result)
  //   this.article = result
  // },
  // 使用fetch api请求数据
  async created() {
    // 动态路由传参 / 路径参数
    // fetch(`https://mock.boxuegu.com/mock/3083/articles/${this.$route.params.id}`)
    // 查询参数传参
    // fetch(`https://mock.boxuegu.com/mock/3083/articles/${this.$route.query.id}`)
    //     .then(response => response.json())
    //     .then((responseData) => {
    //       console.log('response object:',responseData)
    //       const { result } = responseData
    //       this.article = result
    //     })
    //  使用 sync + await 解析 Promise
    const res = await (await fetch(`https://mock.boxuegu.com/mock/3083/articles/${this.$route.query.id}`)).json()
    console.log(res)
    this.article = res.result
  }
}
</script>

<style lang="less" scoped>
[v-cloak] {
  display: none;
}
.article-detail-page {
  .nav {
    height: 44px;
    border-bottom: 1px solid #e4e4e4;
    line-height: 44px;
    text-align: center;
    .back {
      font-size: 18px;
      color: #666;
      position: absolute;
      left: 10px;
      top: 0;
      transform: scale(1, 1.5);
    }
  }
  .header {
    padding: 0 15px;
    p {
      color: #999;
      font-size: 12px;
      display: flex;
      align-items: center;
    }
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
  }
  .body {
    padding: 0 15px;
  }
}
</style>